<?php
	header("content-type:text/html;charset=utf-8");
	$uname = $_POST["uname"];
	$upwd = $_POST["upwd"];
	$db=mysqli_connect("localhost","root","","flower");
	mysqli_query($db,"set names utf8");
	$selSql = "select * from user where uname = '$uname'";
	$selResult = mysqli_query($db,$selSql);
	$arr = mysqli_fetch_array($selResult);
	if($arr){
		echo "<script>
			alert('用户名已存在');
			location.href = 'register.html';
		</script>";
	}else{
		//定义sql语句
		$sql = "insert into user (uname,upwd) values ('$uname','$upwd')";
		//执行sql语句
		$result = mysqli_query($db,$sql);
		if($result){
			echo "<script>
				alert('注册成功');
				location.href = '../login/login.html';
			</script>";
		}else{
			echo "<script>
				alert('注册失败');
				location.href = 'register.html';
			</script>";
		}
	}
?>